app.controller('brandController',function($scope,$controller,brandService){
    $controller('baseController',{$scope:$scope})


    //展示全部页面
    $scope.brandInfo=function (pageNum,pageSize) {
           brandService.brandInfo(pageNum,pageSize).success(
                function (res) {
                    $scope.list=res.rows;
                    $scope.paginationConf.totalItems=res.total
                }
            )
    }
    //新增品牌
    $scope.addInfo=function () {
        const editBrand={
            name:$scope.name,
            firstChar:$scope.firstChar
        }
            brandService.add(editBrand).success(
                function (res) {
                    if (res.flag) {
                        alert('添加成功');
                        $scope.reload();
                    }
                }
            )
    }
    //展示编辑信息
    $scope.showEditInfo=function(brand){
        $scope.id=brand.id;
        $scope.editName=brand.name;
        $scope.editFirstChar=brand.firstChar
    }
    //更新品牌
    $scope.editInfo=function () {
        const editBrand={
            id:$scope.id,
            name:$scope.editName,
            firstChar:$scope.editFirstChar
        }
            brandService.editInfo(editBrand).success(
                function (res) {
                    if (res.flag) {
                        alert('更新成功');
                        $scope.reload();
                    }
                }
            )
    }
    $scope.ids=[];
    //选中/不选单选框
    $scope.getChecked=function ($event,id) {
        if ($event.target.checked){
            $scope.ids.push(id);
        } else {
            const index=$scope.ids.indexOf(id);
            $scope.ids.splice(index,1)
        }
    }
    $scope.checkedAll=function($event){
        if ($event.target.checked) {
            angular.forEach($scope.list,function (brand) {
                $scope.ids.push(brand.id);
            })
        }else{
            $scope.ids=[];
        }
    }
    //删除
    $scope.deleteBrand=function () {
            const data=$scope.ids
            brandService.deleteBrand(data).success(function (res) {
                if (res.flag) {
                    alert('删除成功')
                    $scope.reload();
                }
            })
    }
    //清除表单
    $scope.clear=function () {
        $scope.name='';
        $scope.firstChar='';
    }
    $scope.entity={}
    //关键字查询
    $scope.search=function (pageNum,pageSize) {
           brandService.search(pageNum,pageSize, $scope.entity)
               .success(function (res) {
                $scope.list=res.rows;
                $scope.paginationConf.totalItems=res.total
            })
    }
})